package com.example.userp.app.myapplication;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

/**
 * Describe:
 * Created by ysy on 2018/10/15.
 */
public class TextBehavior extends CoordinatorLayout.Behavior<View> {
    static String  TAG="TAG";
    public TextBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
        Log.e(TAG, "TextBehavior: " );
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
        Log.e(TAG, "layoutDependsOn: ");
        return dependency instanceof TextView;
    }

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        int offset = dependency.getTop() - child.getTop();
        ViewCompat.offsetTopAndBottom(child, offset);
        Log.e(TAG, "onDependentViewChanged: ");
        return true;
    }
}
